<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="排序" prop="sortNum">
        <el-input
          v-model="queryParams.sortNum"
          placeholder="请输入排序"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1男 / 2女 / 3其他" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入1男 / 2女 / 3其他"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="头像" prop="headUrl">
        <el-input
          v-model="queryParams.headUrl"
          placeholder="请输入头像"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="qq号" prop="qq">
        <el-input
          v-model="queryParams.qq"
          placeholder="请输入qq号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微小号" prop="wxNum">
        <el-input
          v-model="queryParams.wxNum"
          placeholder="请输入微小号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电子邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入电子邮箱"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用号吗" prop="backupPhone">
        <el-input
          v-model="queryParams.backupPhone"
          placeholder="请输入备用号吗"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工号" prop="staffNo">
        <el-input
          v-model="queryParams.staffNo"
          placeholder="请输入工号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提成方案id" prop="commissionId">
        <el-input
          v-model="queryParams.commissionId"
          placeholder="请输入提成方案id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位id" prop="postId">
        <el-input
          v-model="queryParams.postId"
          placeholder="请输入岗位id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入职日期" prop="joiningDate">
        <el-date-picker clearable
          v-model="queryParams.joiningDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择入职日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出生日期" prop="birthDate">
        <el-date-picker clearable
          v-model="queryParams.birthDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="招聘渠道" prop="recruitChannel">
        <el-input
          v-model="queryParams.recruitChannel"
          placeholder="请输入招聘渠道"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐人id(公司内部门id)" prop="recommendId">
        <el-input
          v-model="queryParams.recommendId"
          placeholder="请输入推荐人id(公司内部门id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯;个人的祖居地或原籍地，通常是指祖父及以上父系祖先长期居住或户籍登记的地方。" prop="nativePlace">
        <el-input
          v-model="queryParams.nativePlace"
          placeholder="请输入籍贯;个人的祖居地或原籍地，通常是指祖父及以上父系祖先长期居住或户籍登记的地方。"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="民族" prop="ethnicity">
        <el-input
          v-model="queryParams.ethnicity"
          placeholder="请输入民族"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="政治面貌" prop="political">
        <el-input
          v-model="queryParams.political"
          placeholder="请输入政治面貌"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="婚姻情况(未婚 已婚等)" prop="marital">
        <el-input
          v-model="queryParams.marital"
          placeholder="请输入婚姻情况(未婚 已婚等)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最高学历" prop="degree">
        <el-input
          v-model="queryParams.degree"
          placeholder="请输入最高学历"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业年份" prop="graduationYear">
        <el-input
          v-model="queryParams.graduationYear"
          placeholder="请输入毕业年份"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业院校" prop="universityAttended">
        <el-input
          v-model="queryParams.universityAttended"
          placeholder="请输入毕业院校"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="major">
        <el-input
          v-model="queryParams.major"
          placeholder="请输入专业"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCardNo">
        <el-input
          v-model="queryParams.bankCardNo"
          placeholder="请输入银行卡号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户银行" prop="bankName">
        <el-input
          v-model="queryParams.bankName"
          placeholder="请输入开户银行"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保账户" prop="socialAccount">
        <el-input
          v-model="queryParams.socialAccount"
          placeholder="请输入社保账户"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金账户" prop="hpfAccoun">
        <el-input
          v-model="queryParams.hpfAccoun"
          placeholder="请输入公积金账户"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现居住地址" prop="livingAddress">
        <el-input
          v-model="queryParams.livingAddress"
          placeholder="请输入现居住地址"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户口地址" prop="hukoAddress">
        <el-input
          v-model="queryParams.hukoAddress"
          placeholder="请输入户口地址"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急联系人" prop="emergencyContact">
        <el-input
          v-model="queryParams.emergencyContact"
          placeholder="请输入紧急联系人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急联系人电话" prop="emergencyContactPhone">
        <el-input
          v-model="queryParams.emergencyContactPhone"
          placeholder="请输入紧急联系人电话"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机等登陆是否锁定：1锁定 0未锁定" prop="phoneLock">
        <el-input
          v-model="queryParams.phoneLock"
          placeholder="请输入手机等登陆是否锁定：1锁定 0未锁定"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账号状态0 正常 1离职锁定 2拉黑锁定" prop="accountLock">
        <el-input
          v-model="queryParams.accountLock"
          placeholder="请输入账号状态0 正常 1离职锁定 2拉黑锁定"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乐观锁" prop="revision">
        <el-input
          v-model="queryParams.revision"
          placeholder="请输入乐观锁"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createdBy">
        <el-input
          v-model="queryParams.createdBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable
          v-model="queryParams.createdTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新人" prop="updatedBy">
        <el-input
          v-model="queryParams.updatedBy"
          placeholder="请输入更新人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedTime">
        <el-date-picker clearable
          v-model="queryParams.updatedTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最近登陆时间" prop="lastLoginTime">
        <el-date-picker clearable
          v-model="queryParams.lastLoginTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择最近登陆时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['house:admin:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['house:admin:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['house:admin:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['house:admin:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="adminList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="排序" align="center" prop="sortNum" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="手机" align="center" prop="phone" />
      <el-table-column label="1男 / 2女 / 3其他" align="center" prop="gender" />
      <el-table-column label="头像" align="center" prop="headUrl" />
      <el-table-column label="qq号" align="center" prop="qq" />
      <el-table-column label="微小号" align="center" prop="wxNum" />
      <el-table-column label="电子邮箱" align="center" prop="email" />
      <el-table-column label="备用号吗" align="center" prop="backupPhone" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="工号" align="center" prop="staffNo" />
      <el-table-column label="提成方案id" align="center" prop="commissionId" />
      <el-table-column label="部门id" align="center" prop="deptId" />
      <el-table-column label="岗位id" align="center" prop="postId" />
      <el-table-column label="入职日期" align="center" prop="joiningDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.joiningDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birthDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招聘渠道" align="center" prop="recruitChannel" />
      <el-table-column label="推荐人id(公司内部门id)" align="center" prop="recommendId" />
      <el-table-column label="籍贯;个人的祖居地或原籍地，通常是指祖父及以上父系祖先长期居住或户籍登记的地方。" align="center" prop="nativePlace" />
      <el-table-column label="民族" align="center" prop="ethnicity" />
      <el-table-column label="政治面貌" align="center" prop="political" />
      <el-table-column label="婚姻情况(未婚 已婚等)" align="center" prop="marital" />
      <el-table-column label="最高学历" align="center" prop="degree" />
      <el-table-column label="毕业年份" align="center" prop="graduationYear" />
      <el-table-column label="毕业院校" align="center" prop="universityAttended" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNo" />
      <el-table-column label="开户银行" align="center" prop="bankName" />
      <el-table-column label="社保账户" align="center" prop="socialAccount" />
      <el-table-column label="公积金账户" align="center" prop="hpfAccoun" />
      <el-table-column label="现居住地址" align="center" prop="livingAddress" />
      <el-table-column label="户口地址" align="center" prop="hukoAddress" />
      <el-table-column label="紧急联系人" align="center" prop="emergencyContact" />
      <el-table-column label="紧急联系人电话" align="center" prop="emergencyContactPhone" />
      <el-table-column label="手机等登陆是否锁定：1锁定 0未锁定" align="center" prop="phoneLock" />
      <el-table-column label="账号状态0 正常 1离职锁定 2拉黑锁定" align="center" prop="accountLock" />
      <el-table-column label="乐观锁" align="center" prop="revision" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy" />
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最近登陆时间" align="center" prop="lastLoginTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.lastLoginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['house:admin:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['house:admin:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业管理员对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="adminRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="排序" prop="sortNum">
          <el-input v-model="form.sortNum" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="手机" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机" />
        </el-form-item>
        <el-form-item label="1男 / 2女 / 3其他" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入1男 / 2女 / 3其他" />
        </el-form-item>
        <el-form-item label="头像" prop="headUrl">
          <el-input v-model="form.headUrl" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="qq号" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入qq号" />
        </el-form-item>
        <el-form-item label="微小号" prop="wxNum">
          <el-input v-model="form.wxNum" placeholder="请输入微小号" />
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮箱" />
        </el-form-item>
        <el-form-item label="备用号吗" prop="backupPhone">
          <el-input v-model="form.backupPhone" placeholder="请输入备用号吗" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="工号" prop="staffNo">
          <el-input v-model="form.staffNo" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="提成方案id" prop="commissionId">
          <el-input v-model="form.commissionId" placeholder="请输入提成方案id" />
        </el-form-item>
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="岗位id" prop="postId">
          <el-input v-model="form.postId" placeholder="请输入岗位id" />
        </el-form-item>
        <el-form-item label="入职日期" prop="joiningDate">
          <el-date-picker clearable
            v-model="form.joiningDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择入职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="招聘渠道" prop="recruitChannel">
          <el-input v-model="form.recruitChannel" placeholder="请输入招聘渠道" />
        </el-form-item>
        <el-form-item label="推荐人id(公司内部门id)" prop="recommendId">
          <el-input v-model="form.recommendId" placeholder="请输入推荐人id(公司内部门id)" />
        </el-form-item>
        <el-form-item label="籍贯;个人的祖居地或原籍地，通常是指祖父及以上父系祖先长期居住或户籍登记的地方。" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯;个人的祖居地或原籍地，通常是指祖父及以上父系祖先长期居住或户籍登记的地方。" />
        </el-form-item>
        <el-form-item label="民族" prop="ethnicity">
          <el-input v-model="form.ethnicity" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="political">
          <el-input v-model="form.political" placeholder="请输入政治面貌" />
        </el-form-item>
        <el-form-item label="婚姻情况(未婚 已婚等)" prop="marital">
          <el-input v-model="form.marital" placeholder="请输入婚姻情况(未婚 已婚等)" />
        </el-form-item>
        <el-form-item label="最高学历" prop="degree">
          <el-input v-model="form.degree" placeholder="请输入最高学历" />
        </el-form-item>
        <el-form-item label="毕业年份" prop="graduationYear">
          <el-input v-model="form.graduationYear" placeholder="请输入毕业年份" />
        </el-form-item>
        <el-form-item label="毕业院校" prop="universityAttended">
          <el-input v-model="form.universityAttended" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNo">
          <el-input v-model="form.bankCardNo" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="开户银行" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户银行" />
        </el-form-item>
        <el-form-item label="社保账户" prop="socialAccount">
          <el-input v-model="form.socialAccount" placeholder="请输入社保账户" />
        </el-form-item>
        <el-form-item label="公积金账户" prop="hpfAccoun">
          <el-input v-model="form.hpfAccoun" placeholder="请输入公积金账户" />
        </el-form-item>
        <el-form-item label="现居住地址" prop="livingAddress">
          <el-input v-model="form.livingAddress" placeholder="请输入现居住地址" />
        </el-form-item>
        <el-form-item label="户口地址" prop="hukoAddress">
          <el-input v-model="form.hukoAddress" placeholder="请输入户口地址" />
        </el-form-item>
        <el-form-item label="紧急联系人" prop="emergencyContact">
          <el-input v-model="form.emergencyContact" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item label="紧急联系人电话" prop="emergencyContactPhone">
          <el-input v-model="form.emergencyContactPhone" placeholder="请输入紧急联系人电话" />
        </el-form-item>
        <el-form-item label="手机等登陆是否锁定：1锁定 0未锁定" prop="phoneLock">
          <el-input v-model="form.phoneLock" placeholder="请输入手机等登陆是否锁定：1锁定 0未锁定" />
        </el-form-item>
        <el-form-item label="账号状态0 正常 1离职锁定 2拉黑锁定" prop="accountLock">
          <el-input v-model="form.accountLock" placeholder="请输入账号状态0 正常 1离职锁定 2拉黑锁定" />
        </el-form-item>
        <el-form-item label="乐观锁" prop="revision">
          <el-input v-model="form.revision" placeholder="请输入乐观锁" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="form.updatedTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最近登陆时间" prop="lastLoginTime">
          <el-date-picker clearable
            v-model="form.lastLoginTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择最近登陆时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="0 表示未删除，1 表示已逻辑删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入0 表示未删除，1 表示已逻辑删除" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Admin">
import { listAdmin, getAdmin, delAdmin, addAdmin, updateAdmin } from "@/api/house/admin"

const { proxy } = getCurrentInstance()

const adminList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    sortNum: null,
    name: null,
    phone: null,
    gender: null,
    headUrl: null,
    qq: null,
    wxNum: null,
    email: null,
    backupPhone: null,
    idCard: null,
    staffNo: null,
    commissionId: null,
    deptId: null,
    postId: null,
    joiningDate: null,
    birthDate: null,
    recruitChannel: null,
    recommendId: null,
    nativePlace: null,
    ethnicity: null,
    political: null,
    marital: null,
    degree: null,
    graduationYear: null,
    universityAttended: null,
    major: null,
    bankCardNo: null,
    bankName: null,
    socialAccount: null,
    hpfAccoun: null,
    livingAddress: null,
    hukoAddress: null,
    emergencyContact: null,
    emergencyContactPhone: null,
    phoneLock: null,
    accountLock: null,
    revision: null,
    createdBy: null,
    createdTime: null,
    updatedBy: null,
    updatedTime: null,
    lastLoginTime: null,
  },
  rules: {
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询企业管理员列表 */
function getList() {
  loading.value = true
  listAdmin(queryParams.value).then(response => {
    adminList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    sortNum: null,
    name: null,
    phone: null,
    gender: null,
    headUrl: null,
    qq: null,
    wxNum: null,
    email: null,
    backupPhone: null,
    idCard: null,
    staffNo: null,
    commissionId: null,
    deptId: null,
    postId: null,
    joiningDate: null,
    birthDate: null,
    recruitChannel: null,
    recommendId: null,
    nativePlace: null,
    ethnicity: null,
    political: null,
    marital: null,
    degree: null,
    graduationYear: null,
    universityAttended: null,
    major: null,
    bankCardNo: null,
    bankName: null,
    socialAccount: null,
    hpfAccoun: null,
    livingAddress: null,
    hukoAddress: null,
    emergencyContact: null,
    emergencyContactPhone: null,
    phoneLock: null,
    accountLock: null,
    revision: null,
    createdBy: null,
    createdTime: null,
    updatedBy: null,
    updatedTime: null,
    lastLoginTime: null,
    delFlag: null
  }
  proxy.resetForm("adminRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加企业管理员"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getAdmin(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改企业管理员"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["adminRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateAdmin(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addAdmin(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除企业管理员编号为"' + _ids + '"的数据项？').then(function() {
    return delAdmin(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('house/admin/export', {
    ...queryParams.value
  }, `admin_${new Date().getTime()}.xlsx`)
}

getList()
</script>
